package com.liukai.todo_android.common.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * @author ：liukai
 * @date ：Created in 2021/8/16 11:00 上午
 * @description：本地缓存工具类
 * @modified By：
 * @version: $
 */
public class SharedPreferencesUtil {

    public static String getString(Context context, String shareName, String key) {
        SharedPreferences sharedPreferences = getSharedPreferences(context, shareName);
        return sharedPreferences.getString(key, "");
    }

    public static Long getLong(Context context, String shareName, String key) {
        SharedPreferences sharedPreferences = getSharedPreferences(context, shareName);
        return sharedPreferences.getLong(key,0L);
    }

    public static void setString(Context context, String shareName, String key, String value) {
        SharedPreferences sharedPreferences = getSharedPreferences(context, shareName);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString(key, value);
        edit.commit();
    }

    public static void setLong(Context context, String shareName, String key, Long value) {
        SharedPreferences sharedPreferences = getSharedPreferences(context, shareName);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putLong(key, value);
        edit.commit();
    }

    private static SharedPreferences getSharedPreferences(Context context, String shareName){
        LogUtils.e(SharedPreferencesUtil.class,context + ":" + shareName);
        return context.getSharedPreferences(shareName, Context.MODE_PRIVATE);
    }

}
